package com.example.bookstore.entity

import com.fasterxml.jackson.annotation.JsonView
import javax.persistence.*

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/10
 * Time: 13:00
 */
@Table
@Entity
class CarousalEntity : BaseEntity {

    constructor() : super()
    constructor(name: String, imageUrl: String, order: Int, book: BookEntity) : super() {
        this.name = name
        this.imageUrl = imageUrl
        this.order = order
        this.book = book
    }

    @JsonView(CarousalView::class)
    @Column(nullable = false)
    var name: String = ""

    @JsonView(CarousalView::class)
    @Column(nullable = false, unique = true)
    var imageUrl: String = ""

    @JsonView(CarousalView::class)
    @Column(nullable = false, name = "c_order")
    var order: Int = 0

    @JsonView(CarousalWithBookView::class)
    @OneToOne(optional = false)
    @JoinColumn(name = "book_id", unique = true, nullable = false, updatable = false)
    lateinit var book: BookEntity

    interface CarousalView : BaseWithIdView
    interface CarousalWithBookView : CarousalView, BookEntity.BookView
}